package net.sk.china.city.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.sk.china.common.exception.ServiceException;
import net.sk.china.city.utils.PlatformIdHolder;
import net.sk.china.city.service.IArHomeSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.sk.china.city.mapper.ArHomeSupplierMapper;
import net.sk.china.city.domain.ArHomeSupplier;

/**
 * 供应商列表Service业务层处理
 * 
 * @author gxf
 * @date 2024-05-08
 */
@Service
public class ArHomeSupplierServiceImpl implements IArHomeSupplierService
{
    @Autowired
    private ArHomeSupplierMapper arHomeSupplierMapper;

    /**
     * 查询供应商列表
     * 
     * @param id 供应商列表主键
     * @return 供应商列表
     */
    @Override
    public ArHomeSupplier selectArHomeSupplierById(Long id)
    {
        return arHomeSupplierMapper.selectArHomeSupplierById(id);
    }

    /**
     * 查询供应商列表列表
     * 
     * @param arHomeSupplier 供应商列表
     * @return 供应商列表
     */
    @Override
    public List<ArHomeSupplier> selectArHomeSupplierList(ArHomeSupplier arHomeSupplier)
    {
        return arHomeSupplierMapper.selectArHomeSupplierList(arHomeSupplier);
    }

    /**
     * 新增供应商列表
     * 
     * @param arHomeSupplier 供应商列表
     * @return 结果
     */
    @Override
    public int insertArHomeSupplier(ArHomeSupplier arHomeSupplier)
    {
        arHomeSupplier.setPlatformId(PlatformIdHolder.getPlatformId());
        return arHomeSupplierMapper.insertArHomeSupplier(arHomeSupplier);
    }

    /**
     * 修改供应商列表
     * 
     * @param arHomeSupplier 供应商列表
     * @return 结果
     */
    @Override
    public int updateArHomeSupplier(ArHomeSupplier arHomeSupplier)
    {
        return arHomeSupplierMapper.updateArHomeSupplier(arHomeSupplier);
    }

    /**
     * 批量删除供应商列表
     * 
     * @param ids 需要删除的供应商列表主键
     * @return 结果
     */
    @Override
    public int deleteArHomeSupplierByIds(Long[] ids)
    {
//        return arHomeSupplierMapper.deleteArHomeSupplierByIds(ids);
        for(Long id : ids){
            ArHomeSupplier arHomeSupplier = new ArHomeSupplier();
            arHomeSupplier.setId(id);
            arHomeSupplier.setDelFlag("2");
            int i = arHomeSupplierMapper.updateArHomeSupplier(arHomeSupplier);
            if(i <=0 ){
                throw new ServiceException("删除失败",409);
            }
        }
        return 1;
    }

    /**
     * 删除供应商列表信息
     * 
     * @param id 供应商列表主键
     * @return 结果
     */
    @Override
    public int deleteArHomeSupplierById(Long id)
    {
        ArHomeSupplier arHomeSupplier = new ArHomeSupplier();
        arHomeSupplier.setId(id);
        arHomeSupplier.setDelFlag("2");
        int i = arHomeSupplierMapper.updateArHomeSupplier(arHomeSupplier);
        if(i <=0 ){
            throw new ServiceException("删除失败",409);
        }
        return 1;
    }

    @Override
    public List<ArHomeSupplier> getSuppliers(){
        return arHomeSupplierMapper.selectList(new QueryWrapper<ArHomeSupplier>()
                .eq("del_flag","0")
                .like("platform_id","%"+ PlatformIdHolder.getPlatformId() +"%"));
    }
}
